﻿using log4net;
using System.ComponentModel;
using Telerik.Windows.Controls;
using TruckScale.Models;


namespace TruckScale.Views
{
  /// <summary>
  /// Interaction logic for DMGoodsDetailView.xaml
  /// </summary>
  public partial class DMGoodsDetailView : RadWindow, INotifyPropertyChanged
  {
    //log
    private static readonly log4net.ILog log = LogManager.GetLogger("DMGoodsDetailView");
    //新增后同步刷新列表
    public event PropertyChangedEventHandler PropertyChanged;

    public string InfoBar { get; set; }
    public string Theme { get; set; } = Global._weighConfig["Theme"];
    public string MainFontSize { get; set; } = Global._weighConfig["MainFontSize"];
    public GoodsModel Goods { get; set; }
    public DMGoodsDetailView(GoodsModel goods)
    {
      InitializeComponent();
      this.DataContext = this;

      if (goods != null)
      {
        Goods = goods;
      }
      else
      {
        Goods = new GoodsModel();
      }
    }
    private void RadButton_Click(object sender, System.Windows.RoutedEventArgs e)
    {
      InfoBar = string.Empty;
      
      if (Goods.GoodsId == null)
      {
        if (0 < GoodsModel.InsertGoods(Goods))
        {
          this.Close();
        }
        else
        {
          InfoBar = "保存失败，请检查信息是否完整或已存在！";
        }
      }
      else
      {
        if (0 < GoodsModel.UpdateGoods(Goods))
        {
          this.Close();
        }
        else
        {
          InfoBar = "保存失败，请检查信息是否完整或已存在！";
        }
      }
    }
  }
}
